import 'package:flutter/material.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/entities/schedul_child_entity.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/decoration.dart';
import 'package:library_base/res/dividing_line.dart';
import 'package:library_base/res/edge.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/button/ink_bg_well.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:library_base/res/widget_generator.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:module_dispatcher/page/scheduled/scheduled_controller.dart';

Widget buildItem(
  SchedulChildEntity model, {
  Callback<SchedulChildEntity>? onTap,
  Callback<SchedulChildEntity>? onItemClick,
}) {
  List<Widget> widgets = [];

  widgets.add(gapH24);

  widgets.add(GestureDetector(
    onTap: () {
      onTap?.call(model);
    },
    child: Container(
      color: ThemeUtil.getTheme().colorScheme.secondary,
      padding: EdgeInsets.symmetric(horizontal: 24.w),
      child: Row(
        children: [
          Padding(
              padding: EdgeInsets.only(right: 24.w),
              child: LocalImage(model.isSelected ? 'common_checked' : 'common_no_checked',
                  package: Constant.packLib(), width: 34.r, height: 34.r)),
          Expanded(child: Text(model.orderNumber, style: normalTextColor28))
        ],
      ),
    ),
  ));
  widgets.add(gapH24);
  widgets.add(line1);
  widgets.add(Gaps.vwGap18);

  widgets.add(Padding(
      padding: edgeLR24,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text("${MultiLanguage.clientSName.tr} : ", style: normalTextColor28),
          Expanded(
              child: Text("${model.shipperName} /${model.mobilePhone}", style: normalTextColor28)),
        ],
      )));

  widgets.add(Gaps.vwGap18);
  widgets.add(Padding(
      padding: edgeLR24,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text("${MultiLanguage.shippingAddress.tr} : ", style: normalTextColor28),
          Expanded(child: Text(model.address, style: normalTextColor28)),
        ],
      )));

  widgets.add(Gaps.vwGap18);
  widgets.add(Padding(
      padding: edgeLR24,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text("${MultiLanguage.commodityQuantity.tr} : ", style: normalTextColor28),
          Expanded(child: Text(model.count.toString(), style: normalTextColor28)),
        ],
      )));

  widgets.add(Gaps.vwGap18);
  widgets.add(Padding(
      padding: edgeLR24,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text("${MultiLanguage.deliveryTime.tr} : ", style: normalTextColor28),
          Expanded(child: Text(model.stationTime, style: normalTextColor28)),
        ],
      )));

  widgets.add(gapH24);

  return GestureDetector(
    onTap: () {
      onItemClick?.call(model);
    },
    child: roundWidget(
      margin: edgeLR24,
      decoration: rs8,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: widgets,
      ),
    ),
  );
}

Widget buildBottom({
  required ScheduledController baseGetxController,
  required Widget child,
  void Function()? onTap,
  void Function()? platoon,
}) {
  return Container(
    color: Colors.white,
    child: Column(
      children: [
        Expanded(
          child: child,
        ),
        Container(
            height: 166.w,
            decoration: rectTop,
            alignment: Alignment.topRight,
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(child: GetBuilder<ScheduledController>(
                  builder: (logic) {
                    return GestureDetector(
                      onTap: baseGetxController.selectedAll,
                      child: Container(
                        color: Colors.transparent,
                        child: Stack(
                          children: [
                            Positioned(
                              top: 43.w,
                              left: 24.w,
                              child: Row(
                                children: [
                                  LocalImage(
                                      logic.isSelectAll.value
                                          ? 'common_checked'
                                          : 'common_no_checked',
                                      package: Constant.packLib(),
                                      width: 34.r,
                                      height: 34.r),
                                  gapW10,
                                  Text(
                                      MultiLanguage.selectAll2OrdersSelected
                                          .trArgs(["${logic.listDataSelected.length}"]),
                                      style: normalTextColor28)
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    );
                  },
                )),
                GetBuilder<ScheduledController>(
                  builder: (logic) {
                    return GradientButton(
                      ThemeUtil.getTheme(),
                      height: 77.w,
                      width: 184.w,
                      margin: EdgeInsets.only(right: 24.w, top: 21.w),
                      padding: EdgeInsets.symmetric(horizontal: 30.w),
                      text: MultiLanguage.platoon.tr,
                      onPressed: baseGetxController.listDataSelected.value.isEmpty ? null : platoon,
                    );
                  },
                ),
              ],
            )),
      ],
    ),
  );
}
